package com.gjy.comment;

import java.util.HashMap;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2022-12-26 15:15:40
 */
public class AjaxResult extends HashMap<String, Object> {
    private static final long serialVersionUID = 1L;
    public static final String CODE_TAG = "retcode";
    public static final String MSG_TAG = "retinfo";
    public static final String DATA_TAG = "data";
    private ResponseCode responseCode;
    private Object data;

    public AjaxResult() {
    }

    public AjaxResult(ResponseCode responseCode) {
        super.put("retcode", responseCode.getCode());
        super.put("retinfo", responseCode.getMsg());
    }

    public AjaxResult(ResponseCode responseCode, String key, Object data) {
        super.put("retcode", responseCode.getCode());
        super.put("retinfo", responseCode.getMsg());
        super.put(key, data);
    }

    public AjaxResult(ResponseCode responseCode, String msg) {
        super.put("retcode", responseCode.getCode());
        super.put("retinfo", msg);
    }

    public AjaxResult(String code, String msg, Object data) {
        super.put("retcode", code);
        super.put("retinfo", msg);
        super.put("data", data);
    }

    public static AjaxResult ok() {
        return new AjaxResult(AjaxResult.ResponseCode.SUCCESS);
    }

    public static AjaxResult ok(Object data) {
        return new AjaxResult(AjaxResult.ResponseCode.SUCCESS, "data", data);
    }

    public static AjaxResult ok(String key, Object data) {
        return new AjaxResult(AjaxResult.ResponseCode.SUCCESS, key, data);
    }

    public static AjaxResult error() {
        return new AjaxResult(AjaxResult.ResponseCode.ERROR);
    }

    public static AjaxResult error(String msg) {
        return new AjaxResult(AjaxResult.ResponseCode.ERROR, msg);
    }

    public static AjaxResult error(ResponseCode code, String msg) {
        return new AjaxResult(code, msg);
    }

    public AjaxResult put(String key, Object value) {
        super.put(key, value);
        return this;
    }

    public static enum ResponseCode {
        SUCCESS("000000", "成功"),
        ERROR("000001", "系统开小差啦～～"),
        USER_NOT_EXIST("000002", "很抱歉，您没有权限查看或操作"),
        TRACK_POINTS_UPLOAD_ERROR("000003", "非考勤时间，无法上报定位数据");

        private final String code;
        private final String msg;

        private ResponseCode(String code, String msg) {
            this.code = code;
            this.msg = msg;
        }

        public String getCode() {
            return this.code;
        }

        public String getMsg() {
            return this.msg;
        }
    }
}
